package com.bw.a2301club

/**
 * @author ykj
 * @date 2025-09-17 21:37
 * @description
 */
import com.bw.lib_common.base.BaseViewModel
import com.bw.lib_common.base.state.RequestEvent
import com.bw.lib_net.BaseResponse
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.flowOf

/**
 * @author ytx
 * @date 2025-09-17 14:55
 * @description
 */
class MainViewModel:BaseViewModel() {
    private val stateFlow by lazy {
        MutableStateFlow<RequestEvent>(RequestEvent.Init)
    }
    val stateFlow_= stateFlow.asStateFlow()
    //测试BaseViewModel
    fun getData(){
        val response = BaseResponse(200,"模拟网络请求到的数据","")
        val data = flowOf(response)
        execute(data,
            onStart = {
                stateFlow.value = RequestEvent.Loading
            },
            onError = {
                stateFlow.value = RequestEvent.Error(it)
            },
            onFinish = {
                stateFlow.value = RequestEvent.Success
            }
        )

    }

}